﻿<%@ WebService Language="C#" Class="WebService" %>

using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

using com.evaair.mall;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

[WebService(Namespace = "http://evaair.com/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService
{
  /// <summary>
  /// 傳送產品通知MAIL
  /// </summary>
  /// <param name="b2c_code">商品B2C_CODE</param>
  /// <param name="mail_address">欲傳送的Mail Address</param>
  /// <returns></returns>
  [System.Web.Services.WebMethod]
  public string SendProductMail(string b2c_code, string mail_address)
  {
    string result = "-1";
    try
    {
      string url = "~/Services/SendMail.aspx?B2C_CODE=@B2C_CODE&Mail=@Mail";
      HttpContext.Current.Server.Execute(url
        .Replace("@B2C_CODE", b2c_code)
        .Replace("@Mail", mail_address));
      HttpContext.Current.Response.ClearContent();
      result = "Y";
    }
    catch (Exception ex)
    {
      throw ex;
    }
    return result;
  }

  
  /// <summary>
  /// 紀錄產品通知MAIL
  /// </summary>
  /// <param name="b2c_code">商品B2C_CODE</param>
  /// <param name="mail_address">欲紀錄的Mail Address</param>
  /// <returns></returns>
  [System.Web.Services.WebMethod]
  public string SaveFollowMail(string b2c_code, string smas_code , string mail_address)
  {
    string result = "-1";
    try
    {
      //紀錄MAIL
      B2C_MALL_TRACKING ws = new B2C_MALL_TRACKING();
      ws.Url = System.Configuration.ConfigurationManager.AppSettings["B2C_MALL_TRACKING"].ToString(); 
      string jsonString = ws.B2C_MALL_B2C_Save_Product_For_Mail(CommonUtil.GetWebDevice(),
        b2c_code, smas_code , mail_address);
      JObject restoredObject = JsonConvert.DeserializeObject<JObject>(jsonString);
      string Is_Valid = restoredObject["Is_Valid"].ToString();
      string msg = restoredObject["Msg"].ToString();
      if (Is_Valid=="Y")
      {
        HttpContext.Current.Response.ClearContent();
        result = "Y";                
      }
    }
    catch (Exception ex)
    {
      throw ex;
    }
    return result;
  }
}